package com.example.passwordmanager;

import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import com.example.passwordmanager.PasswordRepository;

@Database(entities = {PasswordRepository.class}, version = 1, exportSchema = false)
public abstract class PasswordDatabase extends RoomDatabase {
    private static PasswordDatabase INSTANCE;

    public abstract PasswordDao passwordDao();

    public static synchronized PasswordDatabase getInstance(Context context) {
        if (INSTANCE == null) {
            INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                            PasswordDatabase.class, "password_database")
                    .fallbackToDestructiveMigration()
                    .build();
        }
        return INSTANCE;
    }
}